home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / FilterOutputStream.java < prev    next >
Text File  |  1998-09-22  |  5KB  |  151 lines

  1. /*
  2.  * @(#)FilterOutputStream.java    1.16 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.io;
  16.  
  17. /**
  18.  * This class is the superclass of all classes that filter output 
  19.  * streams. These streams sit on top of an already existing output 
  20.  * stream (the <i>underlying</i> output stream), but provide 
  21.  * additional functionality. 
  22.  * <p>
  23.  * The class <code>FilterOutputStream</code> itself simply overrides 
  24.  * all methods of <code>OutputStream</code> with versions that pass 
  25.  * all requests to the underlying output stream. Subclasses of 
  26.  * <code>FilterOutputStream</code> may further override some of these 
  27.  * methods as well as provide additional methods and fields. 
  28.  *
  29.  * @author  Jonathan Payne
  30.  * @version 1.16, 07/01/98
  31.  * @since   JDK1.0
  32.  */
  33. public
  34. class FilterOutputStream extends OutputStream {
  35.     /**
  36.      * The underlying output stream. 
  37.      *
  38.      * @since   JDK1.0
  39.      */
  40.     protected OutputStream out;
  41.  
  42.     /**
  43.      * Creates an output stream filter built on top of the specified 
  44.      * underlying output stream. 
  45.      *
  46.      * @param   out   the underlying output stream.
  47.      * @since   JDK1.0
  48.      */
  49.     public FilterOutputStream(OutputStream out) {
  50.     this.out = out;
  51.     }
  52.  
  53.     /**
  54.      * Writes the specified <code>byte</code> to this output stream. 
  55.      * <p>
  56.      * The <code>write</code> method of <code>FilterOutputStream</code> 
  57.      * calls the <code>write</code> method of its underlying output stream. 
  58.      *
  59.      * @param      b   the <code>byte</code>.
  60.      * @exception  IOException  if an I/O error occurs.
  61.      * @since      JDK1.0
  62.      */
  63.     public void write(int b) throws IOException {
  64.     out.write(b);
  65.     }
  66.  
  67.     /**
  68.      * Writes <code>b.length</code> bytes to this output stream. 
  69.      * <p>
  70.      * The <code>write</code> method of <code>FilterOutputStream</code> 
  71.      * calls its <code>write</code> method of three arguments with the 
  72.      * arguments <code>b</code>, <code>0</code>, and 
  73.      * <code>b.length</code>. 
  74.      * <p>
  75.      * Note that this method does not call the one-argument 
  76.      * <code>write</code> method of its underlying stream with the single 
  77.      * argument <code>b</code>. 
  78.      *
  79.      * @param      b   the data to be written.
  80.      * @exception  IOException  if an I/O error occurs.
  81.      * @see        java.io.FilterOutputStream#write(byte[], int, int)
  82.      * @since      JDK1.0
  83.      */
  84.     public void write(byte b[]) throws IOException {
  85.     write(b, 0, b.length);
  86.     }
  87.  
  88.     /**
  89.      * Writes <code>len</code> bytes from the specified 
  90.      * <code>byte</code> array starting at offset <code>off</code> to 
  91.      * this output stream. 
  92.      * <p>
  93.      * The <code>write</code> method of <code>FilterOutputStream</code> 
  94.      * calls the <code>write</code> method of one argument on each 
  95.      * <code>byte</code> to output. 
  96.      * <p>
  97.      * Note that this method does not call the <code>write</code> method 
  98.      * of its underlying input stream with the same arguments. Subclasses 
  99.      * of <code>FilterOutputStream</code> should provide a more efficient 
  100.      * implementation of this method. 
  101.      *
  102.      * @param      b     the data.
  103.      * @param      off   the start offset in the data.
  104.      * @param      len   the number of bytes to write.
  105.      * @exception  IOException  if an I/O error occurs.
  106.      * @see        java.io.FilterOutputStream#write(int)
  107.      * @since      JDK1.0
  108.      */
  109.     public void write(byte b[], int off, int len) throws IOException {
  110.     for (int i = 0 ; i < len ; i++) {
  111.         out.write(b[off + i]);
  112.     }
  113.     }
  114.  
  115.     /**
  116.      * Flushes this output stream and forces any buffered output bytes 
  117.      * to be written out to the stream. 
  118.      * <p>
  119.      * The <code>flush</code> method of <code>FilterOutputStream</code> 
  120.      * calls the <code>flush</code> method of its underlying output stream.
  121.      *
  122.      * @exception  IOException  if an I/O error occurs.
  123.      * @see        java.io.FilterOutputStream#out
  124.      * @since      JDK1.0
  125.      */
  126.     public void flush() throws IOException {
  127.     out.flush();
  128.     }
  129.  
  130.     /**
  131.      * Closes this output stream and releases any system resources 
  132.      * associated with the stream. 
  133.      * <p>
  134.      * The <code>close</code> method of <code>FilterOutputStream</code> 
  135.      * calls its <code>flush</code> method, and then calls the 
  136.      * <code>close</code> method of its underlying output stream. 
  137.      *
  138.      * @exception  IOException  if an I/O error occurs.
  139.      * @see        java.io.FilterOutputStream#flush()
  140.      * @see        java.io.FilterOutputStream#out
  141.      * @since      JDK1.0
  142.      */
  143.     public void close() throws IOException {
  144.     try {
  145.       flush();
  146.     } catch (IOException ignored) {
  147.     }
  148.     out.close();
  149.     }
  150. }
  151.